#[derive(Debug)] 

struct User {
    username: String,
    email: String,
    sign_in_count: u64,
    active: bool,
}

struct Rectangle {
    width: u32,
    height: u32,
}
   
impl Rectangle {
    fn area(&self) -> u32 {
        self.width * self.height
    }

    fn wider(&self, rect: &Rectangle) -> bool {
        self.width > rect.width
    }

     fn create(width: u32, height: u32) -> Rectangle {
        Rectangle { width, height }
    }
}

enum Book {
    Papery(u32),
    Electronic(String),
}

fn main() {
    let user1 = User {
        email: String::from("someone@example.com"),
        username: String::from("someusername123"),
        active: true,
        sign_in_count: 1,
    };
    println!("{:#?}", user1);

    let rect1 = Rectangle { width: 30, height: 50 };
    println!("rect1's area is {}", rect1.area());

    let rect2 = Rectangle { width: 40, height: 20 };
    println!("{}", rect1.wider(&rect2));

    //let rect = Rectangle::create(70, 90);
    //println!("{:?}", rect);

    let s = String::from("broadcast");
    let part1 = &s[0..5];
    let part2 = &s[5..9];
    println!("{}={}+{}", s, part1, part2);

    //let mut s = String::from("runoob");
    //let slice = &s[0..3];
    //s.push_str("yes!"); // 错误
    //println!("slice = {}", slice);

    let arr = [1, 3, 5, 7, 9];
    let part = &arr[0..3];
    for i in part.iter() {
        println!("{}", i);
    }
    
    let book = Book::Papery(1001);
    let ebook = Book::Electronic(String::from("url://..."));
}

















